package directory;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class SeeDirectory {
    public static List<String> seeImage(String folderPath) {
        List<String> list = new ArrayList<String>();
        File folder = new File(folderPath);

        //判断文件是否存在和是否是文件夹
        if (folder.exists() && folder.isDirectory()) {
            File[] files = folder.listFiles();
            //判断是否为空
            if (files != null) {
                for (File file : files) {
                    if (!file.isDirectory() && isImageFile(file)) {
                        list.add(file.getAbsolutePath());
                        System.out.println(file.getAbsolutePath());
                    }
                }
            }

            return list;
        } else {
            System.out.println("文件夹不存在或不是文件夹！");
            return null;
        }
    }

    private static boolean isImageFile(File file) {
        String name = file.getName().toLowerCase();
        return name.endsWith(".jpg") || name.endsWith(".jpeg") || name.endsWith(".png") || name.endsWith(".gif") || name.endsWith(".bmp");
    }
}
